home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap2 / 2_2 / testserv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-15  |  935 b   |  45 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. main()
  6. {
  7.     char* server_name;
  8.     printf("Content-type: text/html\n\n");
  9.  
  10.     printf("<HTML>\n");
  11.     printf("<HEAD><TITLE>CGI Script How-to: Test Script</TITLE></HEAD>\n");
  12.     printf("<BODY>\n");
  13.  
  14.     printf("<H1>CGI Script How-to<BR>determine the server's name for self referencing URL's</H1>\n");
  15.  
  16.     server_name = getenv("SERVER_NAME");
  17.  
  18.     if (server_name != NULL)
  19.     {
  20.         char* server_port = getenv("SERVER_PORT");
  21.         char url[256];
  22.         strcpy(url, "http://");
  23.         strcat(url, server_name);
  24.         if (server_port != NULL && strcmp(server_port, "80") != 0)
  25.         {
  26.             strcat(url, ":");
  27.             strcat(url, server_port);
  28.         }
  29.         strcat(url, "/");
  30.         printf("<H2>You can go to the home page of this server with the URL:\n");
  31.         printf("<A HREF=\"%s\">%s</A></H2>\n", url, url);
  32.     }
  33.     else
  34.     {
  35.         printf("<H2>Server cannot be determined</H2>\n");
  36.     }
  37.  
  38.     printf("</BODY></HTML>\n");
  39.     exit(0);
  40. }
  41.  
  42. /*
  43.  * end of testserv.c
  44.  */
  45.